﻿Public Class FrmAreasListado


    Dim classController As New Class_RC_Controller.rc_Mantenimiento()

    Private m_frmAreas As FrmAreas
    Public Property frmAreas() As FrmAreas
        Get
            Return m_frmAreas
        End Get
        Set(ByVal value As FrmAreas)
            m_frmAreas = value
        End Set
    End Property

    Private Sub CargarAreas()
        Dim dt As New DataTable
        dt = classController.get_Area_All(oiml.dbConn, 0, txtDescripcion.Text)
        dgAreas.DataSource = dt
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()

    End Sub

 

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        CargarAreas()
    End Sub

    Private Sub txtDescripcion_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            CargarAreas()

        End If
    End Sub

    Private Sub dgActividades_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        btnEditar_Click_1(sender, e)
    End Sub

    Private Sub dgActividades_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click_1(sender, e)
        End If

    End Sub

    'Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    'End Sub


    Private Sub FrmListadoAreas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgAreas.AutoGenerateColumns = False
        CargarAreas()

    End Sub

    

    Private Sub btnEditar_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgAreas.SelectedRows.Count > 0 Then
                Dim Cod As New Integer
                Cod = dgAreas.SelectedRows(0).Cells(0).Value

                If frmAreas Is Nothing Then
                    frmAreas = New FrmAreas
                    frmAreas.codArea = Cod
                    'If frmServicios.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmAreas.ShowDialog()
                    CargarAreas()
                    frmAreas.Dispose()
                    frmAreas = Nothing
                    'End If
                Else
                    frmAreas.codArea = Cod
                    frmAreas.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub btnCancelar_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    
    Private Sub dgAreas_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgAreas.DoubleClick
        btnEditar_Click_1(sender, e)
    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        '    If frmciudad Is Nothing Then
        frmAreas = New FrmAreas()
        frmAreas.ShowDialog()
        CargarAreas()
    End Sub
End Class